package so.sao.code.service.infrastructure.dozer;

import org.dozer.DozerBeanMapper;
import so.sao.code.service.infrastructure.Constant;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;

/**
 * Created by Administrator on 2017/8/16.
 */
public class Mapper {
    static DozerBeanMapper dozer;

    static {
        List<String> mappingFiles = Arrays.asList(
                Constant.DOZER_MAP_SOURCE + "TagBatchMapper.xml"
        );
        dozer = new DozerBeanMapper();
        dozer.setMappingFiles(mappingFiles);
    }


    public static <T> T map(Object source, Class<T> destinationClass) {
        return dozer.map(source, destinationClass);
    }

    @SuppressWarnings("rawtypes")
    public static <T> List<T> mapList(Collection sourceList, Class<T> destinationClass) {
        List<T> destinationList = new ArrayList<T>();
        for (Object sourceObject : sourceList) {
            T destinationObject = dozer.map(sourceObject, destinationClass);
            destinationList.add(destinationObject);
        }
        return destinationList;
    }
}
